package org.xsm.pinyougou.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xsm.pinyougou.entity.TbSeckillGoods;
import org.xsm.pinyougou.service.SeckillService;
import org.xsm.pinyougou.utils.Result;

import java.util.List;

@RestController
@RequestMapping("/seckillGoods")
public class SeckillIndexController {

    @Autowired
    SeckillService seckillService;


    @Autowired
    RedisTemplate redisTemplate;


    /**
     * 查询所有秒杀物品
     */
    @GetMapping("/findAll")
    public List<TbSeckillGoods> findAll(){

        return seckillService.findAll();
    }

    /**
     * 根据id查1条数据
     */
    @RequestMapping("/findOne/{id}")
    public TbSeckillGoods findOne(@PathVariable("id") Long id){
        return seckillService.findOne(id);
    }

    /**
     * 下单
     */
    @RequestMapping("/saveOrder/{id}")
    public Result saveOrder(@PathVariable("id") Long id){
        String userId = "jiuwenlong";
        return seckillService.saveOrder(id, userId);
    }

}
